﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Content.Master" Inherits="System.Web.Mvc.ViewPage<MethodWorx.CMS.UI.Models.CreatePageTemplateModel>" %>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
        <script language="javascript">
            $(document).ready(function () {


                $("#childChoiceCreate").click(function () {
                    enableDisableChildPageTemplateForm();
                });

                $("#childChoiceAdd").click(function () {
                    enableDisableChildPageTemplateForm();
                });

                $("#cancel").click(function () {
                    window.parent.closeDialog();
                });

                $("#existingPageTemplate").change(setExistingPageTemplateLabel);

                $("#next").click(function () {
                    var canContinue;
                    canContinue = validateStep1();
                    if (canContinue) {
                        $("#step1").hide();
                        $("#step2").show();
                        $("#next").hide();
                        $("#back").show();
                        $("#finish").show();
                    }
                });

                $("#back").click(function () {
                    $("#step1").show();
                    $("#step2").hide();
                    $("#next").show();
                    $("#back").hide();
                    $("#finish").hide();
                });

                enableDisableChildPageTemplateForm();

                //
                //  if we are checked to begin with we can start on step 2
                if ($("input[@name='childChoice']:checked").val() != null) {
                    //  show step 2
                    $("#step1").hide();
                    $("#step2").show();
                    $("#next").hide();
                    $("#back").show();
                    $("#finish").show();
                }
                else {
                    //  show step 1
                    $("#step1").show();
                    $("#step2").hide();
                    $("#next").show();
                    $("#back").hide();
                    $("#finish").hide();
                }

            });

            function validateStep1() {
                $("#existingPageTemplateError").hide();
                if($("input[@name='childChoice']:checked").val() == "create")
                    return true;
                else if($("input[@name='childChoice']:checked").val() == "add")
                {
                    if($("#existingPageTemplate").val() == "")
                    {
                        $("#existingPageTemplateError").show();
                        return false;
                    }
                    else
                        return true;
                }
            }

            function setupFormAction() {
                if ($("input[@name='childChoice']:checked").val() == "create") {
                    $("#createTemplateForm").show();
                    $("#addTemplateForm").hide();
                    $("#inputForm").attr("action", "/PageTemplate/Create");
                }
                else {
                    $("#createTemplateForm").hide();
                    $("#addTemplateForm").show();
                    $("#inputForm").attr("action", "/PageTemplate/Add");
                }

                setExistingPageTemplateLabel();
            }


            function enableDisableChildPageTemplateForm() {
                if ($("input[@name='childChoice']:checked").val() == "create") {
                    $("#childPageTemplateForm").css("color", "silver");
                    $("#existingPageTemplate").attr("disabled", true);
                }
                else if($("input[@name='childChoice']:checked").val() == "add")
                {
                    $("#childPageTemplateForm").css("color", "black");
                    $("#existingPageTemplate").attr("disabled", false);
                }

                setupFormAction();
            }

            function setExistingPageTemplateLabel() {
                $("#pageTemplateName").text($("#existingPageTemplate option:selected").text());
            }

        </script>

        <form id="inputForm" method="post" action="<%=Url.Content("~/PageTemplate/Create")%>">
            <%=Html.Hidden("id") %>
            <div id="step1" style="display:none">
	            <div class="formItem">
    		        <label style="width:200px">Create New Page Template:</label>
                    <%=Html.RadioButton("childChoice", "create", new { id="childChoiceCreate"}) %>
                </div>
                <div class="formItem">
		            <label style="width:200px">Add Existing Page Template:</label>
                    <%=Html.RadioButton("childChoice", "add", new { id="childChoiceAdd"}) %>
	            </div>
	            <div class="formItem" id="childPageTemplateForm">
		            <label style="width:200px">Child Page Template:</label>
                    <%=Html.DropDownList("existingPageTemplate", this.Model.GetExistingPageTemplatesSelectList(), "Please Select...", new { disabled = "disabled" })%>
                    <span id="existingPageTemplateError" class="field-validation-error" style="display:none">Please select a page template</span>
	            </div>
            </div>
            <div id="step2" style="display:none">
                <div class="form">
                    <div id="createTemplateForm">
                        <div class="formItem">
                            <label>Parent Page Template:</label> <%=this.Model.PageTemplate.Name %>
                        </div>
                        <div class="formItem">
		                    <label>Template Name:</label>
                            <%=Html.TextBox("PageTemplateBasicDetails.Name") %><br />
                            <%=Html.ValidationMessage("PageTemplateBasicDetails.Name")%>
                        </div>
                        <div class="formItem">
		                    <label>Template Description:</label>
                            <%=Html.TextArea("PageTemplateBasicDetails.Description", new { rows = 5 })%><br />
                            <%=Html.ValidationMessage("PageTemplateBasicDetails.Description")%>
                        </div>
                    </div>
                    <div class="formItem"id="addTemplateForm">
                        <label>Child Page Template: </label>
                        <span id="pageTemplateName"></span>
                    </div>
                    <div class="formItem">
		                <label>Minimum Required:</label>
                        <%=Html.TextBox("ConstraintDetails.MinimumRequired", null, new { @class="small" })%><br />
                        <%=Html.ValidationMessage("ConstraintDetails.MinimumRequired")%>
                    </div>
                    <div class="formItem">
		                <label>Maximum Allowed:</label>
                        <%=Html.TextBox("ConstraintDetails.MaximumAllowed", null, new { @class="small" })%><br />
                        <%=Html.ValidationMessage("ConstraintDetails.MaximumAllowed")%>
                    </div>
                    <div class="formItem">
		                <label>Name Constraint:</label>
                        <%=Html.TextBox("ConstraintDetails.NameConstraint")%><br />
                        <%=Html.ValidationMessage("ConstraintDetails.NameConstraint")%>
                    </div>
                </div>
            </div>
            <br />
            <button id="next" type="button" style="display:none">Next >></button>
            <button id="back" type="button" style="display:none">Back <<</button>
            <button id="finish" type="submit" name="submit" value="finish" style="display:none">Finish</button>
            <button id="cancel" type="button">Cancel</button>
        </form>
</asp:Content>
